home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / WASTE 1.2 / WASTE Demo ƒ / WEDemoDrags.c < prev    next >
Text File  |  1996-05-19  |  2KB  |  83 lines

  1. /*
  2.     WASTE Demo Project:
  3.     Drag Handlers
  4.  
  5.     Copyright © 1993-1996 Marco Piovanelli
  6.     All Rights Reserved
  7.  
  8.     C port by John C. Daub
  9. */
  10.  
  11. #ifndef __WEDEMOAPP__
  12. #include "WEDemoIntf.h"
  13. #endif
  14.  
  15. // static variables for the drag handlers UPPs
  16.  
  17. static DragTrackingHandlerUPP sMyTrackingHandlerUPP = nil;
  18. static DragReceiveHandlerUPP sMyReceiveHandlerUPP = nil;
  19.  
  20. static pascal OSErr MyTrackingHandler( DragTrackingMessage message, WindowRef window, void *refCon, DragReference drag )
  21. {
  22. #pragma unused (refCon)
  23.  
  24.     DocumentHandle hDocument;
  25.  
  26.     if ( ( window != nil ) && ( ( hDocument = GetWindowDocument( window ) ) != nil ) )
  27.     {
  28.         return WETrackDrag( message, drag, (*hDocument)->we );
  29.     }
  30.  
  31.     return noErr;
  32. }
  33.  
  34. static pascal OSErr MyReceiveHandler( WindowRef window, void *refCon, DragReference drag )
  35. {
  36. #pragma unused (refCon)
  37.  
  38.     DocumentHandle    hDocument;
  39.  
  40.     if ( ( window != nil ) && ( ( hDocument = GetWindowDocument( window ) ) != nil ) )
  41.     {
  42.         return WEReceiveDrag( drag, (*hDocument)->we );
  43.     }
  44.  
  45.     return noErr;
  46. }
  47.  
  48. OSErr InstallDragHandlers( void )
  49. {
  50.     OSErr err;
  51.  
  52.     sMyTrackingHandlerUPP = NewDragTrackingHandlerProc( MyTrackingHandler );
  53.     sMyReceiveHandlerUPP = NewDragReceiveHandlerProc( MyReceiveHandler );
  54.  
  55.     if ( ( err = InstallTrackingHandler( sMyTrackingHandlerUPP, nil, nil ) ) != noErr )
  56.     {
  57.         return err;
  58.     }
  59.  
  60.     if ( ( err = InstallReceiveHandler( sMyReceiveHandlerUPP, nil, nil ) ) != noErr )
  61.     {
  62.         return err;
  63.     }
  64.  
  65.     return noErr;
  66. }
  67.  
  68. OSErr RemoveDragHandlers( void )
  69. {
  70.     OSErr err;
  71.  
  72.     if ( ( err = RemoveTrackingHandler( sMyTrackingHandlerUPP, nil ) ) != noErr )
  73.     {
  74.         return err;
  75.     }
  76.     if ( ( err = RemoveReceiveHandler( sMyReceiveHandlerUPP, nil ) ) != noErr )
  77.     {
  78.         return err;
  79.     }
  80.  
  81.     return noErr;
  82. }
  83.